import {mainNetWork} from "./env"
import { Contract, ethers, providers, utils } from "ethers";
export async function listenerEvent() {
    const main = async () => {
        //1. 创建provider
        const provider = new ethers.providers.JsonRpcProvider(mainNetWork)
        //2. 创建合约实例
        const addressOrName = '0xdac17f958d2ee523a2206206994597c13d831ec7'
        const abi = [
          "event Transfer(address indexed from, address indexed to, uint value)"
        ];
        const contractUSDT = new ethers.Contract(addressOrName,abi,provider)
        //3. 监听合约的事件
        contractUSDT.on('Transfer', (from,to ,value) => {
          console.log(`从 ${from} 钱包地址 向 ${to}钱包转帐了 ${ethers.utils.formatUnits(ethers.BigNumber.from(value), 6)}`)
        })
    }
    main()
}